//package com.bicon.bdata_service_search.log;
//
//import org.springframework.web.HttpMediaTypeNotSupportedException;
//import org.springframework.web.bind.annotation.ControllerAdvice;
//import org.springframework.web.bind.annotation.ExceptionHandler;
//import org.springframework.web.bind.annotation.ResponseBody;
//import org.springframework.web.bind.annotation.RestController;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import javax.servlet.http.HttpServletRequest;
//
///**
// * 描述:
// * global exception
// *
// * @author zhaoyu
// * @email zhaoyu@vv.cc
// * @create 2018-08-22 18:07
// */
//@ControllerAdvice(annotations = {RestController.class})
//public class GlobalExceptionHandler {
//    private Logger logger = LoggerFactory.getLogger(this.getClass());
//    /**
//     * 默认未知异常
//     * @param request
//     * @param e
//     * @return
//     * @throws Exception
//     */
//    @ExceptionHandler(value = Exception.class)
//    @ResponseBody
//    public BaseView defaultErrorHandler(HttpServletRequest request, Exception e) throws Exception {
//        BaseView baseView = new BaseView(CodeConstants.SYSTEM_EXCEPTION,CodeConstants.SYSTEM_EXCEPTION_MSG);
//        printLog(request,e,baseView);
//        return baseView;
//    }
//
//    /**
//     * 参数异常
//     * @param request
//     * @param e
//     * @return
//     * @throws Exception
//     */
//    @ExceptionHandler(value = {HttpMessageNotReadableException.class, MissingServletRequestPartException.class ,MissingServletRequestParameterException.class, MultipartException.class})
//    @ResponseBody
//    public BaseView httpMessageNotReadableExceptionErrorHandler(HttpServletRequest request, Exception e) throws Exception {
//        BaseView baseView = new BaseView(CodeConstants.PARAMETER_ERROR,CodeConstants.PARAMETER_ERROR_MSG);
//        printLog(request,e,baseView);
//        return baseView;
//    }
//    /**
//     * contentType异常
//     * @param request
//     * @param e
//     * @return
//     * @throws Exception
//     */
//    @ExceptionHandler(value = {HttpMediaTypeNotSupportedException.class})
//    @ResponseBody
//    public BaseView httpMediaTypeNotSupportedExceptionHandler(HttpServletRequest request, Exception e) throws Exception {
//        BaseView baseView =  new BaseView(CodeConstants.CONTENTTYPE_ERROR,CodeConstants.CONTENTTYPE_ERROR_MSG);
//        printLog(request,e,baseView);
//        return baseView;
//    }
//
//    /**
//     * 异常信息打印日志
//     * @param request
//     * @param e
//     * @param baseView
//     */
//    private void printLog(HttpServletRequest request, Exception e, BaseView baseView){
//        logger.error(AppUtil.getExceptionDetail(e));
//        LogEntity logEntity = new LogEntity();
//        logEntity.setHttpMethod(request.getMethod());
//        logEntity.setUrl(request.getRequestURL().toString());
//        logEntity.setIp(request.getRemoteAddr());
//        logEntity.setArgs(AppUtil.getRequestBody(request));
//        logEntity.setLogType(AppConstants.LOG_TYPE_HTTP);
//        logEntity.setReqParams(JsonUtil.objectToJson(request.getParameterMap()));
//        logEntity.setRespParams(JsonUtil.objectToJson(baseView));
//        logger.error(">>>"+JsonUtil.objectToJson(logEntity));
//    }
//
//}